<template >
<view class="container">
  <view class="pay-result">
    <view class="success" v-if="status == true">
      <view class="msg">付款成功</view>
      <view class="btns">
        <div class="btn"   @click="redirect">查看订单</div>
        <div class="btn"   @click="payOrder">继续逛</div>
      </view>
    </view>
    <view class="error" v-if="status != true">
      <view class="msg">付款失败</view>
      <view class="tips">
        <view class="p">请在 <text class="time">1小时</text> 内完成付款</view>
        <view class="p">否则订单将会被系统取消</view>
      </view>
      <view class="btns">
        <!-- <navigator  hover-class="none" class="btn" url="/pages/ucenter/order/order" open-type="redirect">查看订单</navigator> -->
        <div class="btn" @click='redirect'>查看订单</div>
 
        <view class="btn" @click='startPay'>重新付款</view>
      </view>
    </view>
  </view>
</view>
</template>

<script>
// import api from '@/utils/api'
import wx from 'wx'
import pay from '@/services/pay'
import util from '@/utils/util'
import api from '@/utils/api'
export default {
  data () {
    return {
      status: false,
      orderId: 0
    }
  },
  async mounted () {
    console.log(this.$route.query.status,556556)
    if (this.$route.query.status) {
      this.status = this.$route.query.status;
    }
    this.orderId = this.$route.query.orderId || 24;
  },
  methods: {
    // 返回订单详情页
    redirect () {
      wx.redirectTo({
        url: '/pages/ucenter/order?order=0'
      })
      
    
    },
   
    payOrder () {
      // pay.payOrder(parseInt(this.orderId)).then(res => {
      //   this.status = true;
      // }).catch(res => {
      //   util.showErrorToast('支付失败');
      // });
        wx.switchTab({
        url: '/pages/index/index'
      })
    },
        async startPay () {  // 重新付款
         let payInfoReq = {}
          payInfoReq = wx.getStorageSync('otherPayData' );
          payInfoReq.payMode = "weChatPay";
          payInfoReq.payClient = "jsapi_buyer_mini";//h5
           payInfoReq.openId = wx.getStorageSync('openId')
          //  'o4jjr4qU9XryOBXACp5yFv3u_Hlw'

//  let data=JSON.stringify({"payProductName":"订单费","payAmnt":10,"orderId":"2c0b8bea556041af9e36094ae55f67df","payProductDesc":"购买Ee","payMode":"weChatPay","payId":"T418112617260000003","payName":"orderPay","payClient":"jsapi_buyer_mini",'openId':'o4jjr4qU9XryOBXACp5yFv3u_Hlw'})
    let data=JSON.stringify(payInfoReq)
    const res = await api.BuyerOrderPay({"data":data});
     
      // console.log('pay页直接支付,请求结果', res);
      // if (res.errno === 0) {
        
        let payParam = res.data.payInfo;
  console.log(payParam)
        wx.requestPayment({
          'timeStamp': payParam.timeStamp,
          'nonceStr': payParam.nonceStr,
          'package': payParam.package,
          'signType': payParam.signType,
          'paySign': payParam.paySign,
          'success': function (res) {
            wx.redirectTo({
              url: '../pay/payResult?status=1'
            })
          },
          'fail': function (res) {
            wx.redirectTo({
              url: '../pay/payResult?status=0'
            })
          }
        })
      // } else {
      //   wx.redirectTo({
      //     url: '../pay/payResult?status=0&orderId=' + this.orderId
      //   })
      // }
    }
  },
  // 原生的分享功能
  onShareAppMessage: function () {
    return {
      title: 'dfcShop',
      desc: '大风车商场',
      path: '/pages/pay/payResult'
    }
  }
}
</script>

<style scoped>
page {
  min-height: 100%;
  width: 100%;
  background: #fff;
}

.container {
  height: 100%;
  background: #fff;
}

.pay-result {
  background: #fff;
}

.pay-result .msg {
  text-align: center;
  margin: 100rpx auto;
  color: #2bab25;
  font-size: 36rpx;
}

.pay-result .btns {
  display: flex;
  align-items: center;
  justify-content: center;
}

.pay-result .btn {
  text-align: center;
  height: 80rpx;
  margin: 0 20rpx;
  width: 200rpx;
  line-height: 78rpx;
  border: 1px solid #868686;
  color: #000000;
  border-radius: 5rpx;
}

.pay-result .error .msg {
  color: #b4282d;
  margin-bottom: 60rpx;
}

.pay-result .error .tips {
  color: #7f7f7f;
  margin-bottom: 70rpx;
}

.pay-result .error .tips .p {
  font-size: 24rpx;
  line-height: 42rpx;
  text-align: center;
}

.pay-result .error .tips .p {
  line-height: 42rpx;
  text-align: center;
}
</style>
